package com.ctriphotel.website;

import com.ctriphotel.website.config.Constants;
import com.ctriphotel.website.config.DefaultProfileUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;

@SpringBootApplication
public class HotelSiteApplication {
	private static final Logger log = LoggerFactory.getLogger(HotelSiteApplication.class);

	public static void main(String[] args) throws UnknownHostException {
		SpringApplication app = new SpringApplication(HotelSiteApplication.class);
		DefaultProfileUtil.addDefaultProfile(app);
		Environment env = app.run(args).getEnvironment();
		Constants.modifyNodeStatusValue("IS_DEV", String.valueOf(Arrays.asList(env.getActiveProfiles()).contains("dev")));
		Constants.modifyNodeStatusValue("DOMAIN", env.getProperty("service.domain"));
		log.info("\n----------------------------------------------------------\n\t" +
						"Application '{}' is running! \n\t" +
						"Run mode is dev: " + Constants.getNodeStatusValue("IS_DEV") +"\n\t" +
						"Access URLs:\n\t" +
						"Local: \t\thttp://127.0.0.1:{}\n\t" +
						"External: \thttp://{}:{}\n----------------------------------------------------------",
				env.getProperty("spring.application.name"),
				env.getProperty("server.port"),
				InetAddress.getLocalHost().getHostAddress(),
				env.getProperty("server.port"));

	}
}
